package com.yy.micro.magic.data.entity;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.yy.micro.magic.data.model.base.JpaObjectWithDynamicFields;
import com.yy.micro.magic.data.model.converter.TypedSetConverter;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;

import javax.persistence.*;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@Proxy(lazy = false)
@Entity
@Table(name = "M_MAGIC_PLAN_SCHEDULE")
public class MagicPlanScheduleEntity extends JpaObjectWithDynamicFields {

    @Id
    @Column(name="PLAN_ID")
    @GeneratedValue(strategy = GenerationType.AUTO,generator = "snowflake")
    @GenericGenerator(name = "snowflake",strategy = SnowflakeIdWorker.NAME)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long planId;

    @Column(nullable = false,name = "PLAN_CODE")
    private String planCode;
    @Column(name = "CATEGORY")
    private String category;
    @Column(name = "DESCRIPTION")
    private String description;
    @Column(name = "VERSION")
    private String version = "1.0";
    @Column(name = "DISABLE")
    private boolean disable = Boolean.FALSE;
    @Column(name = "RULE_LIST")
    @Convert(converter = TypedSetConverter.class)
    private Set<Long> ruleList = new LinkedHashSet<>();

    @Transient
    private List<MagicRuleEntity> rules;

    public List<MagicRuleEntity> getRules() {
        return rules;
    }

    public void setRules(List<MagicRuleEntity> rules) {
        this.rules = rules;
    }

    @Override
    public String getIdProperty() {
        return "schemeId";
    }

    public Long getPlanId() {
        return planId;
    }

    public void setPlanId(final Long planId) {
        this.planId = planId;
    }

    public String getPlanCode() {
        return planCode;
    }

    public void setPlanCode(final String planCode) {
        this.planCode = planCode;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public boolean isDisable() {
        return disable;
    }

    public void setDisable(final boolean disable) {
        this.disable = disable;
    }

    public void setRuleList(Set<Long> ruleList) {
        this.ruleList = ruleList;
    }

    public Set<Long> getRuleList() {
        return ruleList;
    }

}
